<?php

namespace core;
class mastershu{
    
    public static $classMap = array();
    static public function run() {
        $route = new \core\lib\route();
        $ctrlClass = $route->ctrl;
        $action = $route->action;
        $ctrlFile = APP.'/ctrl/'.$ctrlClass.'Ctrl.php';
        $ctrlClass = '\\'.MODULE.'\ctrl\\'.$ctrlClass.'Ctrl';
        if(is_file($ctrlFile)){
            include $ctrlFile;
            $ctrl = new $ctrlClass;
            $ctrl ->$action();
        }else{
            throw new \Exception("Error Processing Request".$ctrlClass);
            
        }
    }
    
    static public function load($class){
        // 自动加载类库
        if(isset($classMap[$class])){
            return true;
        }else{
            $class = str_replace('\\','/',$class);
            $file = MASTERSHU.'/'.$class.'.php';
            if($file){
                include $file;
                self::$classMap[$class] = $class;
            }else{
                return false;
            }
        }
    }

    public function assign($name, $value){
        $this->assign[$name] = $value;
    }

    public function display($file){
        $file = APP.'/view/'.$file;
        if(is_file($file)){
            extract($this->assign);
            include $file;
        }
    }
}